$(function() {
	var $form = $("#updatePwdForm");
	var pwdType = "pass" + "word";
	// 将输入框类型修改为密码类型
	// IE8
	if(document.documentMode == 8){
		var $pwd = $form.find('input[name="pwd"]');
		var $newpwd = $form.find('input[name="newpwd"]');
		var pwdHtml = "<input type=\""+pwdType+"\" class=\"form-control required\" name=\"pwd\" placeholder=\"请输入原密码\">";
		var newpwdHtml = "<input type=\""+pwdType+"\" class=\"form-control required\" name=\"newpwd\" placeholder=\"请输入新密码\">";
		$pwd.parent().html(pwdHtml);
		$newpwd.parent().html(newpwdHtml);
	}else{
		$form.find("input.required").attr("type", pwdType);
	}
	
	//保存
	$("#updatePwdSubBtn").click(function() {
		var isSuccess = true;
		// 对登录表单进行非空校验
		$form.find("input.required").each(function() {
			if ($(this).val() != "") {
				$(this).removeClass("driverVerifcateError");
				return;
			}
			$(this).addClass("driverVerifcateError");
			isSuccess = false;
		});
		// 触发 keyup 事件
		$form.find("input.required").keyup(function() {
			$(this).removeClass("driverVerifcateError");
			if ($(this).val() == "") {
				$(this).addClass("driverVerifcateError");
			}
		});
		//如果验证不成功，则返回false
		if (!isSuccess)return false;

		// 点击确定确认登录请求后台
		var $pwd = $form.find('input[name="pwd"]');
		var $newpwd = $form.find('input[name="newpwd"]');
		$.post($basePath + "/pwd/update", {"pwd":$pwd.val(),"newpwd":$newpwd.val(),}, function(data) {
			if (data.success == true) {
				bootGrowl(data.resultValue, "success");
			} else {
				// 请求失败
				bootGrowl(data.resultValue,"danger");
			}
		});
	});
});